<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <el-row :gutter="20">
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" size="mini" @click="HandlerSeach()">查询</el-button></el-col>
      </el-row>
    </el-card>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row
      style="margin-top: 1%; font-size: 13px">
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryName }}
        </template>
      </el-table-column>
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.industry }}
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          {{ scope.row.manufacturer }}
        </template>
      </el-table-column>

      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          {{ scope.row.manufacturerTel }}
        </template>
      </el-table-column>

      <el-table-column label="店铺名称" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryCategory }}
        </template>
      </el-table-column>

      <el-table-column label="店铺地址" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryNature }}
        </template>
      </el-table-column>

      <el-table-column label="联系人" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryAgency }}
        </template>
      </el-table-column>

      <el-table-column label="电话" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryKind }}
        </template>
      </el-table-column>

      <el-table-column label="营业开始时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryType }}
        </template>
      </el-table-column>

      <el-table-column label="文件" align="center">
        <template slot-scope="scope">
          <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </template>
      </el-table-column>


      <el-table-column label="状态" align="center" width="150">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.review == 1" size="mini">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.review == 2" size="mini">审核通过</el-tag>
          <el-tag type="danger" v-if="scope.row.review ==3" size="mini">审核不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" align="center" width="160">
        <template slot-scope="scope">
          {{ scope.row.creationTime | formatYmd }}
        </template>
      </el-table-column>

      <el-table-column align="center" prop="created_at" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleDetails(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: center">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="where.currentPage" :page-sizes="[10, 15, 20, 25, 30]" :page-size="where.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { getMaterialCompanyById, getMerchantStoreById, saveShop } from "@/api/custom";

  export default {
    filters: {
      statusFilter(status) {
        const statusMap = {
          published: "success",
          draft: "gray",
          deleted: "danger",
        };
        return statusMap[status];
      },
    },
    data() {
      return {
        list: null,
        listLoading: true,
        where: {
          pageSize: 15,
          pageIndex: 1,
          // state: ""
        },
        imageUrl: '',
        total: 0,
      };
    },
    created() {
      this.fetchData(this.where);
    },
    methods: {
      fetchData(obj) {
        this.listLoading = true;
        getMaterialCompanyById(obj)
          .then((response) => {
            console.log(response);
            this.listLoading = false;
            this.list = response.data.list;
            this.total = response.data.total;
          })
          .catch((error) => {
            console.log(error);
          })
          .finally(() => {
            this.listLoading = false;
          });
      },
      handleSizeChange(val) {
        this.where.pageSize = val;
        this.fetchData(this.where);
      },
      handleCurrentChange(val) {
        console.log(val);
        this.where.currentPage = val;
        this.fetchData(this.where);
      },
      HandlerSeach() {
        this.fetchData(this.where);
      },
      // handleDetails(id) {
      //   console.log("Details");
      //   this.$router.push({ name: "RoomDetails", params: { id: id } });
      // },
      handleDetails(id) {
        console.log("Details" + id);
        getMerchantStoreById(id).then((response) => {
          console.log(response);
        });
      },
      HandlerAdd() {
        saveShop(this.form).then((response) => {
          console.log(response);
          this.fetchData(this.where);
        });
      },

      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);

        // 上传成功了
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
      // HandlerAdd() {
      //   this.$router.push({ name: "Addshop" });
      // },
    },
  };
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 56px;
    height: 56px;
    line-height: 56px;
    text-align: center;
  }

  .avatar {
    width: 56px;
    height: 56px;
    display: block;
  }
</style>